import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @projectName: JUC
 * @package: PACKAGE_NAME
 * @className: test
 * @author: 冷环渊 doomwatcher
 * @description: TODO
 * @date: 2022/3/2 23:42
 * @version: 1.0
 */
public class test {
    public static void main(String[] args) {
        //String str = "He15l154lo87wor7l87d";
        double sum = sum2(2);
        System.out.println(sum);
    }

    public static double sum2(int n) {
        // 接收最后结果
        double sum = 0.0;

        // 循环 i的值从1-100
        for (int i = 1; i <= n; i++) {
            // 观察算式，分母是偶数时，分数为负
            if (i % 2 == 0) {
                sum += -(n / i);
            } else {
                sum += (n / i);
            }
        }
        return sum;
    }

    public static void printStrinNum(String str) {
        if (str == null) {
            return;
        }
        String[] split = str.split("\\D");
        ArrayList<Integer> res = new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            if (split[i] == null || "".equals(split[i])) {

            } else {
                res.add(Integer.valueOf(split[i]));
            }
        }
        res.stream().sorted().forEach(System.out::println);

    }

    public static void printNum(String str) {

        //在此输入您的代码...
        int length = str.length();
        List<Integer> list = new ArrayList<>();

        for (int i = 0; i < length; ) {
            if (49 <= str.charAt(i) && 57 >= str.charAt(i)) {
                int j = i + 1;
                while (j < length && 49 <= str.charAt(j) && 57 >= str.charAt(j)) {
                    j++;
                }
                list.add(Integer.valueOf(str.substring(i, j)));
                i = j;
            } else {
                i++;
            }
        }

        Collections.sort(list);
        for (Integer integer : list) {
            System.out.println(integer);
        }
    }

    public static double sum(double sum) {
        double sdouble = 0.0;
        for (int i = 1; i <= sum; i++) {
            sdouble += 1.0 / i;
        }
        return sdouble;
    }


}
